package cn.bone.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ValueFilter;

/**
 * Created by superbone on 2017/3/30.
 */
public class JSONUtil {

    public static String json(Object obj){

        ValueFilter valueFilter = new ValueFilter() {
            /**
             * @param object    class
             * @param name      key
             * @param value     value
             * @return
             */
            @Override
            public Object process(Object object, String name, Object value) {
                if(null==object||null==value){
                    value = "";
                }
                return value;
            }
        };

        return JSON.toJSONString(obj,
                valueFilter,
                SerializerFeature.WriteDateUseDateFormat,
                SerializerFeature.WriteNullListAsEmpty,
                SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteNullBooleanAsFalse);
    }
}
